package com.imut.lagain.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.imut.lagain.entity.HumorMessage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 幽默文案数据访问层
 */
@Mapper
public interface HumorMessageRepository extends BaseMapper<HumorMessage> {
    
    /**
     * 根据心情类型和小偷类型查询幽默文案
     * @param moodType 心情类型
     * @param thiefType 小偷类型
     * @return 幽默文案列表
     */
    @Select("SELECT * FROM humor_message WHERE mood_type = #{moodType} AND thief_type = #{thiefType} AND is_deleted = 0 ORDER BY create_time DESC")
    List<HumorMessage> findByMoodTypeAndThiefType(@Param("moodType") String moodType, @Param("thiefType") String thiefType);
    
    /**
     * 根据心情类型查询幽默文案
     * @param moodType 心情类型
     * @param page 分页参数
     * @return 幽默文案分页列表
     */
    @Select("SELECT * FROM humor_message WHERE mood_type = #{moodType} AND is_deleted = 0 ORDER BY create_time DESC")
    IPage<HumorMessage> findByMoodType(@Param("moodType") String moodType, Page<HumorMessage> page);
    
    /**
     * 根据小偷类型查询幽默文案
     * @param thiefType 小偷类型
     * @param page 分页参数
     * @return 幽默文案分页列表
     */
    @Select("SELECT * FROM humor_message WHERE thief_type = #{thiefType} AND is_deleted = 0 ORDER BY create_time DESC")
    IPage<HumorMessage> findByThiefType(@Param("thiefType") String thiefType, Page<HumorMessage> page);
    
    /**
     * 查询所有未删除的幽默文案
     * @return 幽默文案列表
     */
    @Select("SELECT * FROM humor_message WHERE is_deleted = 0 ORDER BY create_time DESC")
    List<HumorMessage> findAllActive();
    
    /**
     * 根据文案内容模糊查询幽默文案
     * @param message 文案内容关键字
     * @param page 分页参数
     * @return 幽默文案分页列表
     */
    @Select("SELECT * FROM humor_message WHERE message LIKE CONCAT('%', #{message}, '%') AND is_deleted = 0 ORDER BY create_time DESC")
    IPage<HumorMessage> findByMessageLike(@Param("message") String message, Page<HumorMessage> page);
}
